<?php
/**
 * Conversations - A lightweight BB for Xaraya
 *
 * @package modules
 * @copyright (C) 2003-2006 The Digital Development Foundation.
 * @license GPL {@link http://www.gnu.org/licenses/gpl.html}
 * @link http://www.xaraya.com
 *
 * @subpackage conversations
 * @link http://xaraya.com/index.php/release/760.html
 * @author John Cox
*/
/**
 * utility function to pass individual item links to whoever
 *
 * @param $args['itemtype'] item type (1 = tags, 2 = posts)
 * @param $args['itemids'] array of item ids to get
 * @returns array
 * @return array containing the itemlink(s) for the item(s).
 * @todo fix the post array.  
        since we don't have a title for the post, 
        i am using the tag title.  I think i need a
        left join somewhere
 */
function conversations_userapi_getitemlinks($args)
{
    extract($args);
    $itemlinks = array();

    // tags
    if (empty($itemtype)) {
        $tags = xarModAPIFunc('conversations', 'user', 'gettags');
        if (empty($tags)) {
            return $itemlinks;
        }
        foreach ($tags as $tag) {
            if (!empty($itemids) && !in_array($tag['id'], $itemids)) continue;
            $itemlinks[$tag['id']] = array(
                'url'   => xarModURL('conversations', 'user', 'viewtag', array('id' => $tag['id'])),
                'title' => xarML('View Tag'),
                'label' => $tag['tag']
            );
         }
    } else {
        // posts
        if (empty($itemids)) {
            $posts = xarModAPIFunc('conversations', 'user', 'getposts', array('tagid' => $itemtype));
        } else {
            $posts = xarModAPIFunc('conversations', 'user', 'getposts', array('postid' => $itemids));
        }
        if (empty($posts)) {
            return $itemlinks;
        }
        foreach ($posts as $post) {
            $itemlinks[$post['postid']] = array(
                'url'   => xarModURL('conversations', 'user', 'viewpost', array('postid' => $post['postid'])),
                'title' => xarML('View Post'),
                //'label' => $topic['ttitle']) have to think about this.  Do I need to do a left join instead?
            );
        }
    }
    return $itemlinks;
}
?>